#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<iostream>
using namespace std;
int jewelleryValue(vector<vector<int>>& frame) {
    int m = frame.size(); int n = frame[0].size();
    vector<vector<int>> dp(m, vector<int>(n));
    int i = 0; int j = 0;
    int count = 0;
    while (i < m) { dp[i][0] = frame[i][0]+count; count += frame[i][0]; ++i; }
    count = 0;
    while (j < m) { dp[0][j] = frame[0][j]+count; count += frame[0][j]; ++j; }

    for (i = 1; i < m; i++)
        for (j = 1; j < n; j++)
            dp[i][j] = frame[i][j] + max(dp[i - 1][j], dp[j - 1][i]);
    return dp[m - 1][n - 1];

}
int main()
{
    vector<vector<int>>v1(2, vector<int>(3));
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 3; j++)
        {
            int tmp = 0;
            cin >> tmp;
            v1[i][j] = tmp;
        }
    jewelleryValue(v1);
}